package com.eeepay.eeepay_v2.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.widget.Toast;

import com.eeepay.v2_library.dialog.CustomDialog;
import com.eeepay.v2_library.dialog.DialogUtil;

/**
 * Created by zw on 2016/4/28 0028.
 */
public class ABBaseFragment extends Fragment {

    protected Context mContext;
    protected CustomDialog progressDialog;
    private Toast mToast;

    public void showProgressDialog() {
        if (progressDialog == null) {
            progressDialog = DialogUtil.getHorizontalProgressDialog(mContext);
        }
        progressDialog.show();
    }

    public void showProgressDialog(String string) {
        if (progressDialog == null  ) {
            progressDialog = DialogUtil.getHorizontalProgressDialog(mContext, string);
        }
        progressDialog.show();
    }

    public void dismissProgressDialog() {
        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
    }

    /**
     * 重写此方法，发起异步异步请求
     *
     * @param taskId
     *            异步请求任务id
     */
    protected void sendHttpRequest(int taskId) {

    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getActivity();
    }

    public void showToast(final String text) {
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (mToast == null) {
                    mToast = Toast.makeText(mContext, text, Toast.LENGTH_LONG);
                } else {
                    mToast.setText(text);
                    mToast.setDuration(Toast.LENGTH_SHORT);
                }
                mToast.show();
            }
        });
    }
}
